package com.wadesss.flyingformationapp

import android.app.Application
import android.bluetooth.BluetoothManager
import android.bluetooth.BluetoothSocket
import android.widget.Toast
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.google.android.material.textfield.TextInputEditText
import com.inuker.bluetooth.library.BluetoothClient
import io.dronefleet.mavlink.MavlinkConnection
import java.io.DataInputStream
import java.io.DataOutputStream
import java.net.InetSocketAddress
import java.net.Socket
import java.nio.ByteBuffer
import kotlin.properties.Delegates


class App : Application() {

    lateinit var mClient: BluetoothClient
    var bluetoothSocket: BluetoothSocket? = null
    lateinit var bluetoothManager: BluetoothManager
    lateinit var localBroadcastManager: LocalBroadcastManager
    lateinit var mOutut: DataOutputStream
    lateinit var mInput: DataInputStream
    lateinit var mOutut2: DataOutputStream
    lateinit var mInput2: DataInputStream
    var mSocket = Socket()
    var mMac: String = ""
    var isRun = false
    lateinit var mavlinkConnection: MavlinkConnection
    lateinit var mavlinkConnection2: MavlinkConnection

    // 编队系统用户名密码
    var UserName = ""
    var Passwd = ""

    override fun onCreate() {
        super.onCreate()
        instance = this
        mClient = BluetoothClient(this.applicationContext)
        localBroadcastManager = LocalBroadcastManager.getInstance(applicationContext)

        val pref = getSharedPreferences("Configure", 0)
        UserName = pref.getString("UserName", "").toString()
        Passwd = pref.getString("Passwd", "").toString()
    }

    companion object {
        var instance: App by Delegates.notNull()
    }
}